package com.djl.rabbitmq.eight;

import com.djl.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * @program: rabbitmq-hello
 * @description:死信队列 生产者
 * @author: Mr.dai
 * @create: 2021-09-13 15:13
 **/

public class Producer {
    public static  final  String NORMAL_EXCHANGE="normal_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);
        //死信消息 设置TTl时间 tiome to live
        //AMQP.BasicProperties basicProperties=new AMQP.BasicProperties().builder().expiration("10000").build();
        for (int i=0;i<10;i++){
            String message="info"+i;
            channel.basicPublish(NORMAL_EXCHANGE,"zhangsan",null,message.getBytes(StandardCharsets.UTF_8));
            System.out.println("生产者发送消息:"+message);
        }
    }
}
